package com.ly.test.config;/**
 * Created by Administrator on 2017/1/17.
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author liuyi
 * @date 2017/01/17 19:21
 */
@RestController
public class FinalExceptionHandler implements ErrorController {

    private final Logger logger = LoggerFactory.getLogger(FinalExceptionHandler.class);

    @RequestMapping(value = "/error", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String error(HttpServletResponse resp, HttpServletRequest req) {
        // 错误处理逻辑
        logger.error("404!");
        return "404";
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
